package com.demo.admin.config;

import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;

/**
 * 针对 http 异步优化
 *
 * @author YT
 * @date 2019-07-01
 */
@Configuration
@AllArgsConstructor
public class SpringMvcConfig {

    private final AsyncSupportConfigurer asyncSupportConfigurer;

    @Bean
    public void configThreadPoll() {
        ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
        threadPool.setCorePoolSize(10);
        threadPool.setMaxPoolSize(400);
        threadPool.setQueueCapacity(200);
        threadPool.initialize();
        asyncSupportConfigurer.setTaskExecutor(threadPool);
    }
}
